/**
 * 当鼠标移进书籍名称输入文本框的时候将会触发这个事件
 */
function focusName(massege,inputText) {
	document.getElementById(massege).className = "add_info";
	document.getElementById(inputText).className = "input_txtFocus";
}
function focusEmail(massege,inputText){
	document.getElementById(massege).innerHTML="电子邮箱为全站唯一";
	document.getElementById(massege).className = "add_info";
	document.getElementById(inputText).className = "input_txtFocus";
}
function blurEmail(massege,inputText){
	var span = document.getElementById(massege);
	span.innerHTML="电子邮箱为全站唯一";
	var book_name = document.getElementById(inputText);
	book_name.className = "input_text";
	var bookName = book_name.value;
	if(bookName.length < 5 ||bookName.length > 20) {
		span.className = "add_error";
		return false;
	} else {
		span.className = "add_succeed";
		/*如果是电子邮件失去焦点的话需要做如下的工作*/
		checkUser("/mapping/user/action_checkUser.go?user.userEmail="+bookName,massege);
		return true;
	}
}
function blurName(massege,inputText){
	var span = document.getElementById(massege);
	
	var book_name = document.getElementById(inputText);
	book_name.className = "input_text";
	var bookName = book_name.value;
	if(bookName.length < 3 ||bookName.length > 20) {
		span.className = "add_error";
		return false;
	} else {
		span.className = "add_succeed";
		return true;
	}
}
//密码严重比较特殊
function blurPassWord(massege,inputText){
	var span = document.getElementById(massege);
	
	var book_name = document.getElementById(inputText);
	book_name.className = "input_text";
	var bookName = book_name.value;
	if(bookName.length < 6 ||bookName.length > 16) {
		span.className = "add_error";
		return false;
	} else {
		/*如果输入的字符数都是有效范围的话*/
		if(inputText=='passWord'){//密码框失去焦点
			var rePassWord = document.getElementById('rePassWord').value;
			if(rePassWord.length>0){
				if(bookName!=rePassWord){
					document.getElementById('rePass_Word').innerHTML="两次输入的密码不一致";
					document.getElementById('rePass_Word').className = "add_error";
					
					span.className = "add_succeed";
					return false;
				}
			}
		}else{//如果是再次输入密码框失去焦点
			var rePassWord = document.getElementById('passWord').value;
			if(rePassWord!=bookName){
				span.innerHTML="两次输入的密码不一致";
				span.className = "add_error";
				return false;
			}else{
				span.innerHTML="请再输入一遍您上面输入的密码。";
			}
		}
		span.className = "add_succeed";
		return true;
	}
}

function checkUser(url,div){
	var xmlhttp;
	if(window.XMLHttpRequest) {
		// 如果是 IE7+, Firefox, Chrome, Opera, Safari这些浏览器将会以下面这张方式创建
		xmlhttp = new XMLHttpRequest();
	} else {
		// 如果是 IE6, IE5将会以下面的两种方式创建
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			//如果小于等于0就说明里面还没有内容，这时候就需要说明可能是第一次切换到该界面需要到数据库查询书籍
			document.getElementById(div).innerHTML =  xmlhttp.responseText;
			document.getElementById(div).className = "add_info";
		}
	}
	xmlhttp.open("GET", url, true);
	xmlhttp.send();
}